<template>
	<view class="">
		<view class="list">
			<view class="list-item" v-for="(item,index) in tableData" :key="index">
				<view class="img">
					<image src="@/static/doc/qusetion.png" mode=""></image>
				</view>
				<view class="u-flex-1 " style="min-width: 0;"  @click="getDetail(item.id)">
					<view class="title u-line-1">
						{{item.title}}
					</view>
					<view class="">
						{{item.date}}
					</view>
				</view>
			</view>
		</view>
		<u-empty v-show="tableData.length <= 0" style="margin-top:100rpx" text="暂时没有数据" mode="list"></u-empty>
		<u-loadmore style="margin-top: 30rpx" v-show="tableData.length > 0" :status="status" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				tableData: [],
				page: 1,
				size: 9,
				total: 0
			}
		},
		onLoad() {
			this.getBusinessFaq()
		},
		methods: {
			getDetail(id) {
				console.log(id)
				uni.navigateTo({
					url: `./detail?id=${id}&type=1`
				})
			},
			onReachBottom() {
				if(this.tableData.length >= this.total) return ;
				this.status = 'loading';
				this.page = ++ this.page;
				setTimeout(() => {
					this.getBusinessFaq()
					if(this.tableData.length >= this.total) this.status = 'nomore';
					else this.status = 'loading';
				}, 2000)
			},
			getBusinessFaq() {
				this.$u.api.businessFaq({
					page: this.page,
					size: this.size
				}).then(res => {
					if(res.code == 0){
						if (res.data.length > 0) {
							this.tableData = [...this.tableData, ...res.data];
						} else {
							// 分页结束
							this.status = 'nomore';
						}
						if (this.tableData.length  >= this.total) {
							this.status = 'nomore';
						}
						this.total = res.extraInfo;
					}else{
						uni.showToast({
							icon:'none',
						    title: res.msg
						});
					}
				})
			}
		}
	}
</script>

<style scoped>
	.list-item {
		display: flex;
		padding: 35rpx 30rpx 17rpx 30rpx;
		border-bottom: 1rpx solid #F0F0F0;
		color: #7B7B7B;
		font-size: 24rpx;
	}
	.img {
		margin-right: 15rpx;
		/* width: 48rpx; */
	}
	.img image {
		width: 48rpx;
		height: 48rpx;
	}
	.title {
		margin-bottom: 20rpx;
		color: #000000;
		font-size: 26rpx;
		font-weight: bold;
	}
</style>
